﻿@{
     Layout = "~/Views/Shared/_Layout.cshtml";
    ViewBag.BodyClass = "easyui-layout";
}
<div id="tbtool" class="gou-toolbar" style="padding:3px;">
    <span>名称:</span>
    <input id="searchKey" name="searchKey" maxlength="25" style="line-height:26px;border:1px solid #ccc">
    <a href="javascript:;" class="easyui-linkbutton" iconcls="icon-search" onclick="Search();">查找</a>
    <a href="javascript:void(0);" onclick="access(0);" class="easyui-linkbutton" iconcls="icon-add">新增</a>
</div>
<table id="grid" data-options="region:'center',border:false" class="easyui-datagrid"
       rownumbers="true" fitcolumns="true" singleselect="true" fit="true" pagesize="50"></table>

@section Script{
<script src="/admin/common/scripts/Log.js?v=@ViewBag.JsVersion"></script>
    <script type="text/javascript">
        $(function () {   
            $('#grid').datagrid({
                url: 'GetList?name=' + $("#searchKey").val(),
                columns: [[
                     { field: 'AdminUserGroupName', title: '名称', width: 80 }
                    , { field: 'Code', title: 'Code', width: 100 }
                    , { field: 'Email', title: '邮箱', width: 100 }
                    , { field: 'SortOrder', title: '排序', width: 50 }
                    , { field: 'Remark', title: '描述', width: 100 }
                    , {
                        field: 'StopFlag', title: '状态', width: 50, formatter: function (val, row, index) {
                            var state = (row.StopFlag) ? "禁用" : "启用";
                            return "<span>" + state + "</span>";
                        }
                    }
                    , { field: '_operate', title: '操作', width: 100, align: 'center', formatter: formatOper }
                ]],
                toolbar: '#tbtool',
                pagination: true
            });
            var pager = $('#grid').datagrid('getPager');	// get the pager of datagrid
            pager.pagination({
                showPageList: true,
                pageSize: 50
            });

        });

        function formatOper(val, row, index) {
            var rek = "";
            var cor = "";
            var opt = "";
            if (row.StopFlag) {
                rek = "启用";
                cor = "green";
                opt = '<a href="javascript:void(0);" onclick="updateState(\'' + row.AdminUserGroupId + '\',0,\'' + row.AdminUserGroupName + '\');">启用</a>&nbsp|';
            }
            else {
                rek = "禁用";
                cor = "red";
                opt = '<a href="javascript:void(0);" onclick="updateState(\'' + row.AdminUserGroupId + '\',1,\'' + row.AdminUserGroupName + '\');">禁用</a>&nbsp|';
            }
            opt = opt + '&nbsp<a href="javascript:void(0);" onclick="access(\'' + row.AdminUserGroupId + '\');">编辑</a>&nbsp|&nbsp;<a href="javascript:void(0);" onclick="deleteUser(\'' + row.AdminUserGroupId + '\',\'' + row.AdminUserGroupName + '\');">删除</a>&nbsp|&nbsp<a href="javascript:void(0);" onclick="accessRule(\'' + row.AdminUserGroupId + '\');">权限</a>&nbsp';
            
       
                
            @*if ("True" == "@is_btn_base") {
                opt = '<a href="javascript:void(0);" onclick="editItem(\'' + row.GroupGuID + '\');">编辑</a>&nbsp|'
                + '&nbsp<a href="javascript:void(0);" style="color:' + cor + '" onclick="StopUse(\'' + row.GroupGuID + '\',\'' + row.GroupName + '\',\'' + rek + '\');">' + rek + '</a>&nbsp|';
            }*@
            return opt ;
        }

        function Search() {
            $('#grid').datagrid("load", {
                name: $("#searchKey").val()
            });
        }
        function StopUse(id, name, rek) {
            $.messager.confirm(rek, "你确定" + rek + "”" + name + "“吗?", function (istrue) {
                if (istrue) {
                    $.post("/UserGroup/StopUsing", { id: id }, function (data) {
                        if (data == -1) {
                            $.messager.alert("提示", "操作失败！");
                        }
                        else if (data == -2) {
                            $.messager.alert("提示", "操作失败, 存在正在进行的派发任务！");
                        }
                        else if (data == 1) {
                            $.messager.alert("提示", "操作成功！");
                            $("#grid").datagrid("reload");
                        }
                    });
                }
            });
        }

        function updateState(id, state,name) {
            var rek = state == 1 ? "禁用" : "启用";

            $.messager.confirm(rek, "你确定" + rek + "”" + name + "“吗?", function (istrue) {
                if (istrue) {
                    var param = { AdminUserGroupId: id };
                    $.ajax({
                        "type": "Post",
                        "url": "ajaxUpdateState?t=" + new Date().getTime(),
                        "dataType": "text",
                        "data": param,
                        "success": function (data) {
                            if (data == "True") {
                                $.messager.alert('提示', '操作成功!');
                                $("#grid").datagrid("reload");
                            }
                        }
                    });
                }
            });
            
        }


        function deleteUser(id,name) {
            var rek = "删除";
            $.messager.confirm(rek, "你确定" + rek + "”" + name + "“吗?", function (istrue) {
                if (istrue) {
                    var param = { AdminUserGroupId: id };
                    $.ajax({
                        "type": "Post",
                        "url": "ajaxDelete?t=" + new Date().getTime(),
                        "dataType": "text",
                        "data": param,
                        "success": function (data) {
                            if (data == "True") {
                                $.messager.alert('提示', '删除成功!');
                                $("#grid").datagrid("reload");
                            }
                        }
                    });
                }
            });           
        }

        function access(id) {
            window.location.href = "access?id=" + id;
        }        

        function accessRule(id) {
            window.location.href = "MenuList?adminGroupId=" + id;
        }

    </script>
}







